#!/usr/bin/python
# label: { 
#     url: url,
#     stuffs: 
#     {
#        item : { pattern:pattern, message:message, expression:[lambda, p1, p2], matched:[ val, ref ] },
#        ...
#     },
#     contact:[ from, to, topic ]
# }
import re
import logging

class Predef:

    doors = [ "5mins", "15mins", "30mins", "1hour", "4hours", "8hours", "12hours", "1day" ]

    pattern='pattern'
    message='message'
    expression='expression'
    matched='matched'
    stuffs='stuffs'
    url='url'
    pattern='pattern'
    message='message'
    contact='contact'

    url_='http://'
    url1_='https://'

    expression_=['1==1', '0', '0']

    matched_= [ '0','0' ]
    contact_=['acqu-center <acqu.center@gmail.com>', 'acqu-center@googlegroups.com', 'A notification from acqu-center.']

    @staticmethod
    def isValidEmail(s):
        if s is not None:
            m = re.search(r'\w+@\w+\.\w+',s)
            if m is not None:
                return True
        return False

    @staticmethod
    def isValidHttp(s):
        return (s.startswith(Predef.url_) or s.startswith(Predef.url1_))

    @staticmethod
    def checkMatched(e):
        for i in range(len(e)):
            if e[i]=='':
                e[i]=Predef.matche_[i]
        return e

    @staticmethod
    def checkExpression(e):
        for i in range(len(e)):
            if e[i]=='':
                e[i]=Predef.expression_[i]
        return e

    @staticmethod
    def genMessage(o,n):
        return '{0}<p>{1}</p>'.format(o,n)
